﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using HotelG11.Models;

namespace HotelG11.Controllers
{
    [Authorize(Roles = "LOAINV3")]
    public class NVTiepTanController : Controller
    {
        //
        // GET: /NVTiepTan/

        public ActionResult Index()
        {
            /*try
            {
                if (Session["LoaiTK"].ToString() != "LOAINV3")
                    Response.Redirect("NVTiepTan/Error");
            }
            catch (Exception ex)
            {
                Response.Redirect("NVTiepTan/Error");
            }*/

            G11KhachSanEntities G11 = new G11KhachSanEntities();
            ViewBag.DP = G11.G11_DatPhong.ToList();

            return View();
        }
        [HttpGet]
        public ActionResult ReservationInfo(string maDP)
        {
            G11KhachSanEntities G11 = new G11KhachSanEntities();
            ViewBag.TT = G11.sp_LayThongTinDatPhong(maDP);
            ViewBag.TTKH = G11.sp_LayTTKhachHangDP(maDP);
            ViewBag.TTCT = G11.sp_LayTTCongtyDP(maDP);
            return PartialView();
        }

        [HttpGet]
        public ActionResult RoomAvailable(string maDP)
        {
            G11KhachSanEntities G11 = new G11KhachSanEntities();
            ViewBag.DSP = G11.sp_LayDSPhongTrong(maDP);
            return PartialView();
        }

        [HttpGet]
        public ActionResult ChangeRoom(string maDP, string PO, string PN)
        {
            G11KhachSanEntities G11 = new G11KhachSanEntities();
            ViewBag.TTP = G11.sp_CapNhatPhongDat(maDP, PO, PN);
            ViewBag.maDP = maDP;
            return PartialView();
        }

        public ActionResult RoomArrange(string maDP)
        {
            /*try
            {
                if (Session["LoaiTK"].ToString() != "LOAINV3")
                    Response.Redirect("NVTiepTan/Error");
            }
            catch (Exception ex)
            {
                Response.Redirect("Error");
            }*/

            G11KhachSanEntities G11 = new G11KhachSanEntities();

            ViewBag.maDP = maDP;

            ViewBag.DP = G11.sp_LayDSChiDatPhong();

            ViewBag.CTDP = G11.sp_LayChiTietDatPhong(maDP);

            ViewBag.TT = G11.sp_LayThongTinDatPhong(maDP);

            ViewBag.TTKH = G11.sp_LayThongTinDatPhong(maDP);
            
            return View();
        }

        [HttpGet]
        public ActionResult UpdateResidentInfo(string maDSDP, string tenNguoiO, string CMND)
        {
            G11KhachSanEntities G11 = new G11KhachSanEntities();
            G11.sp_ThemTTNguoiO(maDSDP, tenNguoiO, CMND);
            return PartialView();
        }

        public ActionResult CheckIn(string maDP)
        {
            /*try
            {
                if (Session["LoaiTK"].ToString() != "LOAINV3")
                    Response.Redirect("NVTiepTan/Error");
            }
            catch (Exception ex)
            {
                Response.Redirect("Error");
            }*/

            //if (maDP == null)
            //    Response.Redirect("");

            //Session["maDP"] = "DP00000001";
            //maDP = Session["maDP"].ToString();

            G11KhachSanEntities G11 = new G11KhachSanEntities();
            ViewBag.maDP = maDP;

            ViewBag.DP = G11.sp_LayDSChiDatPhong();

            ViewBag.TT = G11.sp_LayThongTinDatPhong(maDP);
            
            ViewBag.CTDP = G11.sp_LayChiTietDatPhongCI(maDP);                       

            return View();
        }

        public ActionResult DoCheckIn(string maDP)
        {
            G11KhachSanEntities G11 = new G11KhachSanEntities();
            G11.sp_CheckIn(maDP);
            ViewBag.maDP = maDP;
            Response.Redirect("CheckIn");

            return View();
        }

        public ActionResult CheckOut(string maDP)
        {
            /*try
            {
                if (Session["LoaiTK"].ToString() != "LOAINV3")
                    Response.Redirect("NVTiepTan/Error");
            }
            catch (Exception ex)
            {
                Response.Redirect("Error");
            }*/

            G11KhachSanEntities G11 = new G11KhachSanEntities();
            ViewBag.DP = G11.sp_LayDSDaNhanPhong();
            ViewBag.CTDP = G11.sp_LayChiTietDatPhongCO(maDP);
            ViewBag.maDP = maDP;

            return View();
        }

        public ActionResult DoCheckOut(string maDP)
        {

            G11KhachSanEntities G11 = new G11KhachSanEntities();
            G11.sp_CheckOut(maDP);            

            Response.Redirect("CheckOut");
            return View();
        }

        [HttpGet]
        public ActionResult ServiceUsed()
        {
            G11KhachSanEntities G11 = new G11KhachSanEntities();
            ViewBag.DV = G11.G11_DSDichVu;
            return PartialView();
        }

        [HttpGet]
        public ActionResult AddServiceUsed(string maDSDP, string maDV, int soLuong)
        {
            G11KhachSanEntities G11 = new G11KhachSanEntities();

            G11.sp_ThemDVSuDung(maDSDP, maDV, soLuong);
            
            return PartialView();
        }

        public ActionResult Error()
        {
            ViewBag.Message = "Đăng nhập thất bại";
            return View();
        }

    }
}
